<?php

namespace app\home\controller;

use app\home\controller\Common;
use think\Db;
use think\facade\Env;

class Card extends Common
{
    public function post()
    {
        $data = input('post.');
        $data['created_at'] = time();
        $data['updated_at'] = time();
        $point = substr($data['data'],6,2);
        $number = substr($data['data'],-10,-2);
        $temp = '';
        for ($i = 0; $i < strlen($number);) {
            $temp .= strrev((substr($number, $i, 2)));
            $i += 2;
        }
        $number = base_convert(strrev($temp),16,10);
        $data['number'] = str_pad($number,10,"0",STR_PAD_LEFT);
        $data['point'] = base_convert($point, 16, 10);
        $r = db('card_logs')->insertGetId($data);
        if ($r) {
            $json['status'] = 1;
            $json['message'] = lang('success');
            /*********************记录日志***********************/
            addLog(session('card_logs') . '添加记录-' . $data['number'] . ' [ ID:' . $r . ' ]');
            echo json_encode($json);
            exit;
        } else {
            $json['status'] = 0;
            $json['message'] = lang('fail');
            echo json_encode($json);
            exit;
        }

    }



}
